package com.sc.nft.controller;

import com.sc.nft.annotation.UserLogin;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.dto.ActivityCouponsProductDTO;
import com.sc.nft.entity.dto.UserCouponsDTO;
import com.sc.nft.entity.vo.ActivityCouponsProductVO;
import com.sc.nft.entity.vo.UserCanCouponsVO;
import com.sc.nft.entity.vo.UserCouponsProductVO;
import com.sc.nft.entity.vo.UserCouponsVO;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.UserCouponsService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author liGen
 * @version 1.0
 * @date 2023/12/7 5:00 下午
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/ipMall/user/coupons")
@Api(tags = "优惠券模块")
public class UserCouponsController {

    private final UserCouponsService userCouponsService;

    @ApiOperation(value = "用户优惠券列表", notes = "优惠券列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<UserCouponsDTO>> userCouponsDTOList(@RequestBody UserCouponsVO userCouponsVO) {
        List<UserCouponsDTO> userCoupons = userCouponsService.getUserCoupons(UserPool.getUser().getId(),userCouponsVO.getStatus());
        return Result.success(userCoupons);
    }

    @ApiOperation(value = "获取用户购买商品可用优惠券", notes = "获取用户购买商品可用优惠券", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getUserCanCoupons", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<UserCouponsDTO>> getUserCanCoupons(@RequestBody UserCanCouponsVO userCanCouponsVO) {
        List<UserCouponsDTO> userCoupons = userCouponsService.getUserCanCoupons(UserPool.getUser().getId(),userCanCouponsVO.getActivityProductId(),userCanCouponsVO.getOrderPrice());
        return Result.success(userCoupons);
    }

    @ApiOperation(value = "用户优惠券下可用的商品列表", notes = "优惠券下可用的商品列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/productList", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<ActivityCouponsProductDTO> getActivityCouponsProductDTOPage(@Valid @RequestBody UserCouponsProductVO userCouponsProductVO) {
        return PageResult.success(userCouponsService.getActivityCouponsProductDTOPage(userCouponsProductVO));
    }
}
